package com.lagou.rpc.consumer.utils;

import org.springframework.beans.factory.FactoryBean;

/**
 * @Author 梅松
 * @Date 2021/9/5 14:31
 */
public class RpcProxyFactoryBean<T> implements FactoryBean<T> {
    private Class<T> rpcInterface;

    public Class<T> getRpcInterface() {
        return rpcInterface;
    }

    public void setRpcInterface(Class<T> rpcInterface) {
        this.rpcInterface = rpcInterface;
    }

    public RpcProxyFactoryBean() {
    }

    public RpcProxyFactoryBean(Class<T> rpcInterface) {
        this.rpcInterface = rpcInterface;
    }

    @Override
    public T getObject() throws Exception {
        return RpcClientProxy.getRpcClient(this.rpcInterface);
    }

    @Override
    public Class<?> getObjectType() {
        return this.rpcInterface;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

}
